//
//  Cloud_tableViewCellFour.m
//  EggSteward
//
//  Created by 王道林 on 16/9/1.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "Cloud_tableViewCellFour.h"
#import "BaseView.h"
#import "Masonry.h"

@interface Cloud_tableViewCellFour ()
@property (nonatomic, strong) BaseView *View;
@property (nonatomic, strong) UIView *viewLineO;
@property (nonatomic, strong) UIView *viewLineT;

@end
@implementation Cloud_tableViewCellFour

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubview];
        [self notification];
    }
    return self;
}
- (void)notification
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"day" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dayTime:) name:@"day" object:nil];
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    BOOL is = [userDefault boolForKey:@"night"];
    if (is == NO) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"day" object:nil userInfo:nil];
    }
}
- (void)dayTime:(NSNotification *)sender
{
    self.contentView.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
}

- (void)createSubview
{
    self.contentView.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    // 背景view
    _View = [[BaseView alloc] init];
    _View.backgroundColor = [UIColor whiteColor];
    _View.layer.masksToBounds = YES;
    _View.layer.cornerRadius = 10;
    [self.contentView addSubview:_View];
    // lable
    _lableCheck = [[BaseLabel alloc] init];
    _lableCheck.text = @"疾病排查";
    [_View addSubview:_lableCheck];
    _lableHealth = [[BaseLabel alloc] init];
    _lableHealth.text = @"健康体检";
    [_View addSubview:_lableHealth];
    // button
    _buttonCheck = [BaseButton buttonWithType:UIButtonTypeCustom];
    [_buttonCheck setBackgroundImage:[UIImage imageNamed:@"iconfont-xuanzhong11"] forState:UIControlStateNormal];
    [_buttonCheck addTarget:self action:@selector(buttonCheckAction:) forControlEvents:UIControlEventTouchUpInside];
    [_View addSubview:_buttonCheck];

    _buttonHealth = [BaseButton buttonWithType:UIButtonTypeCustom];
    [_buttonHealth setBackgroundImage:[UIImage imageNamed:@"iconfont-xuanzhong11"] forState:UIControlStateNormal];
    [_buttonHealth addTarget:self action:@selector(buttonHealthAction:) forControlEvents:UIControlEventTouchUpInside];
    [_View addSubview:_buttonHealth];

    // 横线
    _viewLineO = [[UIView alloc] init];
    _viewLineO.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    [_View addSubview:_viewLineO];
    _viewLineT = [[UIView alloc] init];
    _viewLineT.backgroundColor = [UIColor colorWithWhite:0.909 alpha:1.000];
    [_View addSubview:_viewLineT];
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    [_View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).mas_offset(20);
        make.right.mas_equalTo(self.contentView.mas_right).mas_offset(-20);
        make.top.mas_equalTo(self.contentView.mas_top);
        make.bottom.mas_equalTo(self.contentView.mas_bottom);
    }];
    // button
    [_buttonCheck mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(20);
        make.top.mas_equalTo(_View.mas_top).mas_offset(10);
        make.height.mas_equalTo(_View.mas_height).multipliedBy(0.3);
        make.width.mas_equalTo(_View.mas_height).multipliedBy(0.3);
    }];
    [_buttonHealth mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(20);
        make.bottom.mas_equalTo(_View.mas_bottom).mas_offset(-10);
        make.height.mas_equalTo(_View.mas_height).multipliedBy(0.3);
        make.width.mas_equalTo(_View.mas_height).multipliedBy(0.3);
    }];
    // lable 的约束
    [_lableCheck mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_buttonCheck.mas_right).mas_offset(20);
        make.top.mas_equalTo(_View.mas_top);
        make.height.mas_equalTo(_View.mas_height).multipliedBy(0.5);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
    }];
    [_lableHealth mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_buttonHealth.mas_right).mas_offset(20);
        make.top.mas_equalTo(_lableCheck.mas_bottom);
        make.height.mas_equalTo(_View.mas_height).multipliedBy(0.5);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
    }];
    
    // 横条
    [_viewLineO mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(10);
        make.top.mas_equalTo(_lableCheck.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(1);
    }];
    // 横条
    [_viewLineT mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_View.mas_left).mas_offset(10);
        make.top.mas_equalTo(_lableHealth.mas_bottom);
        make.right.mas_equalTo(_View.mas_right).mas_offset(-10);
        make.height.mas_equalTo(1);
    }];
    
}
// button的点击事件
- (void)buttonCheckAction:(BaseButton *)button
{
    button.selected = !button.selected;
    if (button.selected == 0) {
        [button setBackgroundImage:[UIImage imageNamed:@"iconfont-xuanzhong11"] forState:UIControlStateNormal];
    }
    if (button.selected == 1) {
        [button setBackgroundImage:[UIImage imageNamed:@"iconfont-xuanzhong"] forState:UIControlStateSelected];
    }
}

- (void)buttonHealthAction:(BaseButton *)button
{
    button.selected = !button.selected;
    if (button.selected == 0) {
        [button setBackgroundImage:[UIImage imageNamed:@"iconfont-xuanzhong11"] forState:UIControlStateNormal];
    }
    if (button.selected == 1) {
        [button setBackgroundImage:[UIImage imageNamed:@"iconfont-xuanzhong"] forState:UIControlStateSelected];
    }
}


@end
